package com.uniknow.app.ui;

import roboguice.activity.RoboActivity;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.uniknow.app.AppManager;
import com.uniknow.app.R;
import com.uniknow.app.util.StringUtils;
import com.uniknow.app.widget.LoadingDialog;

/**
 * 应用程序Activity的基类
 * @author lianjiao (http://www.lianjiao.net)
 * @version 1.0
 * @created 2012-9-18
 */
public class BaseActivity extends RoboActivity{
	private LoadingDialog loding;
	public Context mContext;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		mContext = this;
		//添加Activity到堆栈
		AppManager.getAppManager().addActivity(this);
	}

	@Override
	protected void onDestroy() {
		super.onDestroy();
		//结束Activity&从堆栈中移除
		AppManager.getAppManager().finishActivity(this);
	}
	
	/**
	 * 显示加载等待对话框
	 */
	public void showLoading(){
		if(loding==null){
			loding = new LoadingDialog(this);
		}
		loding.show();
	}
	/**
	 * 关闭加载等待对话框
	 */
	public void closeLoading(){
		if(loding!=null && loding.isShowing()){
			loding.cancel();
		}
		
	}
	
	public void setTitle(String text){
		if(findViewById(R.id.header_btn_center) == null)return;
		((TextView)findViewById(R.id.header_btn_center)).setText(text);
	}
	
	public void showRight(String text){
		if(findViewById(R.id.header_btn_right) == null)return;
		if(StringUtils.isEmpty(text)){
			findViewById(R.id.header_btn_right).setVisibility(View.INVISIBLE);
			((TextView)findViewById(R.id.header_btn_right)).setText(text);
		}else{
			findViewById(R.id.header_btn_right).setVisibility(View.VISIBLE);
			((TextView)findViewById(R.id.header_btn_right)).setText(text);
		}
	}
	
	public void showLeft(String text){
		if(findViewById(R.id.header_btn_left) == null)return;
		if(StringUtils.isEmpty(text)){
			findViewById(R.id.header_btn_left).setVisibility(View.INVISIBLE);
			((TextView)findViewById(R.id.header_btn_left)).setText(text);
		}else{
			findViewById(R.id.header_btn_left).setVisibility(View.VISIBLE);
			((TextView)findViewById(R.id.header_btn_left)).setText(text);
		}
	}
	
}
